package cn.school.teacher.evaluation.dao;

import cn.school.teacher.evaluation.dto.TeacherEvaluationDataDto;
import cn.school.teacher.evaluation.dto.UserDto;
import cn.school.teacher.evaluation.dto.TeacherEvaluationUserTaskDto;
import cn.school.teacher.evaluation.entity.TeacherEvaluationUserTask;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TeacherEvaluationUserTaskDao extends BaseMapper<TeacherEvaluationUserTask> {

    /**
     * 获取任务的打分人列表数据
     */
    @Select(value = "" +
            "select" +
            "   syus.id, syus.username  " +
            "from" +
            "   t_teacher_evaluation_user_task teua LEFT JOIN t_sys_user syus on (    " +
            "       teua.user_id = syus.id  " +
            "   )  " +
            "${ew.customSqlSegment}")
    public List<UserDto> getSoreUserList(@Param("ew") QueryWrapper<TeacherEvaluationUserTask> queryWrapper);


    /**
     * 获取我的任务数据
     */
    @Select(value = "" +
            "select" +
            "   teut.id as teut_id, teut.user_id as user_id, teut.teut_status,  teutUser.username as teut_username, teut.create_time, teut.modify_time, " + // 用户子任务
            "   teta.id teta_id, teta.teta_name, teta.teta_cover_user_id, tetaUser.username as teta_cover_username, teta.teta_status, teta.teta_user_is_visit   " + // 主任务
            "from  " +
            "   t_teacher_evaluation_user_task teut LEFT JOIN t_teacher_evaluation_task teta on (   " +
            "       teut.teta_id = teta.id  " +
            "   ) left JOIN t_sys_user teutUser on (    " +
            "       teut.user_id = teutUser.id  " +
            "   ) left JOIN t_sys_user tetaUser on (    " +
            "       teta.teta_cover_user_id = tetaUser.id   " +
            "   )   " +
            "${ew.customSqlSegment}")
    Page<TeacherEvaluationUserTaskDto> getPage(Page<TeacherEvaluationUserTaskDto> page,@Param("ew") QueryWrapper<TeacherEvaluationUserTaskDto> queryWrapper);


    @Select(value = "" +
            "-- 打分任务详情\n" +
            "select \n" +
            "   teut.id as teut_id, teut.user_id, teut.teut_status,  teutUser.username as teut_username, teut.create_time, teut.modify_time, -- 我的任务\n" +
            "   teta.id as teta_id, teta.teta_name, teta.teta_cover_user_id, tetaUser.username as teta_cover_username, teta.teta_status,  -- 主任务\n" +
            "   teit.id as teit_id, teit.teit_parent_id, teit.teit_content, tesi.tesi_percent,  -- 考评项\n" +
            "   teda.id as teda_id,teda.teda_percent, teda.teda_comment, teda.teda_point --  打分数据\n" +
            "from \n" +
            "   t_teacher_evaluation_user_task teut LEFT JOIN t_teacher_evaluation_task teta on (\n" +
            "       teut.teta_id = teta.id\n" +
            "   ) left JOIN t_sys_user teutUser on (\n" +
            "       teut.user_id = teutUser.id\n" +
            "   )left JOIN t_sys_user tetaUser on (\n" +
            "       teta.teta_cover_user_id = tetaUser.id\n" +
            "   ) LEFT JOIN t_teacher_evaluation_sche_item tesi  on (\n" +
            "       teta.tesc_id = tesi.tesc_id\n" +
            "   ) LEFT JOIN t_teacher_evaluation_item teit on (\n" +
            "       tesi.teit_id = teit.id\n" +
            "   ) LEFT JOIN t_teacher_evaluation_data teda on (\n" +
            "           teda.teut_id = teut.id\n" +
            "       and\n" +
            "           teda.teit_id = teit.id\n" +
            "   )\n" +
            "${ew.customSqlSegment}")
    List<TeacherEvaluationDataDto> getTaskItemData(@Param("ew") QueryWrapper<TeacherEvaluationDataDto> dataDtoQueryWrapper);
	
    /**
     * 获取主任务的所有打分的总分
     * @author fangjin.tao
     * @param: tetaId
     * @updateTime 2022/12/7 15:42
     * @return: java.lang.Double
     */
	Double getSumScore(@Param("tetaId") Long tetaId);
}
